package com.hungryinlindholmen;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class editServlet
 * 
 * Receives a request from ownerresult.jsp and creates a editDb object depending
 * on parameters received. The parameter editDone is set to null. Forwards to
 * owner.jsp with parameters editDone and restID.
 * 
 * @author Ludvig Gee
 */

@WebServlet("/editServlet")
public class editServlet extends HttpServlet {
    private static final long serialVersionUID = 1L;

    @Override
    protected void doGet(HttpServletRequest request,
	    HttpServletResponse response) throws ServletException, IOException {

	String restID = (String) request.getSession().getAttribute("restID");
	String optionEdit = (String) request.getSession().getAttribute(
		"optionEdit");
	String dishAla = (String) request.getSession().getAttribute("dishAla");
	String dishLunch = (String) request.getSession().getAttribute(
		"dishLunch");
	System.out.print(dishLunch);
	String edit_1 = request.getParameter("edit_1");
	String edit_2 = request.getParameter("edit_2");
	String edit_3 = request.getParameter("edit_3");
	String edit_4 = request.getParameter("edit_4");
	String edit_5 = request.getParameter("edit_5");
	String edit_6 = request.getParameter("edit_6");
	String edit_7 = request.getParameter("edit_7");
	request.setAttribute("editDone", null);

	editDb edit = new editDb(restID);
	edit.editUpdate(restID, optionEdit, dishAla, dishLunch, edit_1, edit_2,
		edit_3, edit_4, edit_5, edit_6, edit_7);

	request.setAttribute("restID", edit.getRestID());
	request.setAttribute("editDone", edit.getEditDone());
	RequestDispatcher dispatcher = request
		.getRequestDispatcher("owner.jsp");
	dispatcher.forward(request, response);
    }

}
